# Contributor: lauren n. liberda <lauren@selfisekai.rocks>
# Maintainer:
pkgname=qflipper
pkgver=1.3.3
pkgrel=1
_nanopb=0.4.8
_libwdi=1.5.0
pkgdesc="Flipper Zero firmware updater"
url="https://update.flipperzero.one/"
arch="all"
license="GPL-3.0-only"
makedepends="
	chrpath
	libusb-dev
	qt6-qt5compat-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtserialport-dev
	qt6-qtsvg-dev
	qt6-qttools-dev
	qt6-qtwayland-dev
	zlib-dev
	"
subpackages="$pkgname-gui"
source="$pkgname-$pkgver.tar.gz::https://github.com/flipperdevices/qFlipper/archive/refs/tags/$pkgver.tar.gz
	nanopb-$_nanopb.tar.gz::https://github.com/nanopb/nanopb/archive/$_nanopb.tar.gz
	libwdi-$_libwdi.tar.gz::https://github.com/pbatard/libwdi/archive/v$_libwdi.tar.gz
	"
builddir="$srcdir/qFlipper-$pkgver"
options="!check" # no suite

prepare() {
	default_prepare

	mkdir -p build

	rmdir 3rdparty/nanopb
	ln -sfv "$srcdir"/nanopb-$_nanopb 3rdparty/nanopb
	rmdir driver-tool/libwdi
	ln -sfv "$srcdir"/libwdi-$_libwdi driver-tool/libwdi
}

build() {
	cd build

	qmake6 ../qFlipper.pro \
		PREFIX=/usr \
		-spec linux-g++ \
		CONFIG+=qtquickcompiler \
		INSTALLS.CONFIG+=nostrip \
		QMAKE_CFLAGS="$CFLAGS" \
		QMAKE_CXXFLAGS="$CXXFLAGS" \
		QMAKE_LFLAGS="$LDFLAGS" \
		DEFINES+=DISABLE_APPLICATION_UPDATES

	make
}

package() {
	make -C build INSTALL_ROOT="$pkgdir" install

	# TODO: how to make qmake not do this
	chrpath -d "$pkgdir"/usr/bin/*
	chrpath -d "$pkgdir"/usr/lib/qFlipper/plugins/libflipperproto0.so
}

gui() {
	pkgdesc="$pkgdesc (qt6 gui)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove \
		usr/bin/qFlipper \
		usr/share
}

sha512sums="
55f19517982dbcc52f586bafd1c6f3d9acc9c81c29e3f42bc4e4d2f09c962b976bfb97406e20c7a126b9f555b2e6b6e420fa94cd97b07877d00ef74e425e6751  qflipper-1.3.3.tar.gz
635577498dfbfb46fd64b8ec83b2a4a9b03b57c665f3c9f67d35c272810c0330b0e9011d7c0e43623e9da74d6ee3a4c1f012878e2bff7e1a7e57fb7c0857ad42  nanopb-0.4.8.tar.gz
a70dbf1652228d2fc27968b76c0b92a737c29a3ad6dbc4494a0f6ebd39a539f5155c02e4aaeb437a3b4ba017e61e5e297776163ae94b838a753d467de37b7c0c  libwdi-1.5.0.tar.gz
"
